package com.lyl.goods.mapper;

import com.lyl.goods.pojo.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper {
    @Insert("insert into products(name, price, stock, description) VALUES (#{name},#{price},#{stock},#{description})")
    void add(String name, Integer price, Integer stock, String description);

    @Select("SELECT id, name, price, stock, description FROM products")
    List<Product> getAllProducts();

    @Select("select * from products where id=#{id}")
    Product selectById(Long id);

    @Update("UPDATE products SET name=#{name}, price=#{price}, stock=#{stock}, description=#{description} WHERE id=#{id}")
    void updateById(Product product);

    @Delete("delete from products where id=#{id}")
    void delete(Long id);


    @Select("SELECT * FROM products LIMIT #{offset}, #{limit}")
    List<Product> getProductList(@Param("offset") int offset, @Param("limit") int pageSize);

    @Select("SELECT COUNT(*) FROM products")
    int getTotalCount();

    @Delete("delete from products where id=#{id}")
    void deleteById(Integer id);

    @Select("select *from products where id=#{productId}")
    List<Product> getProduct(Integer productId);

    //删除商品
    @Delete("delete from products where id = #{id}")
    void deleteProduct(Integer id);

    //批量删除
    void batchDeleteProducts(List<Integer> selectedProductIds);
}
